'''
Author: duliang thinktanker@163.com
Date: 2024-02-02 21:56:13
LastEditors: duliang thinktanker@163.com
LastEditTime: 2024-02-02 21:56:17
FilePath: \spot-the-differences-\click_test.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
import tkinter as tk


def on_item_click(event):
    item_id = event.widget.find_withtag(tk.CURRENT)
    print("Item clicked:", item_id)


root = tk.Tk()
canvas = tk.Canvas(root, width=300, height=200)
canvas.pack()

rect_id = canvas.create_rectangle(0, 0, 300, 200)
oval_id = canvas.create_oval(100, 75, 200, 125, fill="red")
text_id = canvas.create_text(150, 100, text="Click me!")

canvas.tag_bind(rect_id, "<Button-1>", on_item_click)
canvas.tag_bind(oval_id, "<Button-1>", on_item_click)
canvas.tag_bind(text_id, "<Button-1>", on_item_click)

root.mainloop()
